home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- #
- # use CGI.pm and DBI external modules
- #
- # CGI.pm is part of standard perl distribution
- # DBI is available from www.cpan.org
- #
- # program uses CSV files to store data
- #
-
- use CGI;
- use DBI;
- use CGI::Carp qw(fatalsToBrowser);
-
- #
- # new instance of cgi
- #
-
- my $q = new CGI;
-
- sub print_table {
-
- my $description = shift;
- my $variable = shift;
-
- #
- # set up for database access
- # ref: O'Reilley CGI Programming with Perl
- #
-
- my $dbdir = "/Library/WebServer/CGI-Executables";
- #my $dbdir = "C:/Documents and Settings/richard/My Documents/Projects/machack";
- my $dbh = DBI->connect("DBI:CSV:f_dir=$dbdir")
- or die "Can't connect: " . $DBI::errstr;
-
- my $sql = "select user, $variable, days from data order by user";
-
- my $sth = $dbh->prepare($sql)
- or die "Can't prepare: " . $dbh->errstr();
-
- $sth->execute()
- or die "Can not execute: " . $sth->errstr();
-
- my @row;
-
- print qq`
- <table border="1">
- <tr><td>User</td><td>$description</td></tr>
- `;
-
- my $i = 0;
- my @list;
- my $msg_avg;
-
- while (@row = $sth->fetchrow_array()){
- $msg_avg = int $row[1] / $row[2];
- if ($variable eq "usage_avg_day"){
- $msg_avg = int $msg_avg / 60;
- }
- @list[$i] = "<tr><td>" .$row[0] . "</td><td>" . $msg_avg . "</td></tr>\n";
- print @list[$i];
- $i++;
- }
-
- print qq`
- </table>
- <br>
- `;
-
- $sth->finish;
-
- $dbh->disconnect;
- }
-
- #
- # tell browser what mime type file is
- #
-
- print $q->header("text/html");
-
- print qq`
- <html>
- <head>
- </head>
- <body bgcolor="FFCC33">
- `;
-
- print qq`
- <h2>Received messages</h2>
- `;
-
- &print_table("Read Messages Per Day", "read_msg_avg_day");
-
- print qq`
- <h2>Sent messages</h2>
- `;
-
- &print_table("Sent Messages Per Day", "sent_msg_avg_day");
-
- print qq`
- <h2>Usage in Minutes</h2>
- `;
-
- &print_table("Average Usage Per Day", "usage_avg_day");
-
- print qq`
- </body>
- </html>
- `;
-